<?php

/**
 * aboutus actions.
 *
 * @package    costabravasfr
 * @subpackage aboutus
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class aboutusActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
  
  }
  
  public function executeFaq(sfWebRequest $request)
  {
	$this->getResponse()->setTitle("Foire aux questions sur la location | Costa Bravas");
  }

  public function executeConditions(sfWebRequest $request)
  {
	sfProjectConfiguration::getActive()->loadHelpers(array('I18N'));
	$this->getResponse()->setTitle(__("termsAndConditions")." | Begur Holidays");
  }
 
  public function executeAvertissementLegal(sfWebRequest $request)
  {
	$this->getResponse()->setTitle("Avertissement legal de Costa Brava's | Costa Bravas");
  }
 
  public function executeContactez(sfWebRequest $request)
  {
	$this->form = new ContactEmailsForm();
  }
  
  public function executeSendContact(sfWebRequest $request)
  {
	$this->forward404Unless($request->isMethod('post'));
    $this->form = new ContactEmailsForm();
    $this->processForm($request, $this->form);
	
  }
  
public function executeMerci()
{
}
  
  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()));
    if ($form->isValid())
    {
      	  $text = "Message reçu de mail:".$form->getValue('email')."Nombre:".$form->getValue('name')."Mensaje: ".$form->getValue('mensaje')."IP: ".$form->getValue('ip')."Casas visitadas: ".$form->getValue('casasvisitadas');
	  
	try
	{
		 $contact_emails = $form->save();
	  // Send
		$this->getMailer()->composeAndSend(
			sfConfig::get('app_email_from'),
			sfConfig::get('app_email_to'),
			'Begur Holidays Contactez nous - ',
			$text." id: ".$contact_emails['id']
		); 

	}
	catch (Exception $e)
	{
	  
	  return $this->renderText($form ['email']."--Un probleme: ".$form['name']->render());
	  // handle errors here
	}

	  
	  $params = array(
		'name'    => $form->getValue('name'),
		'email'    => $form->getValue('email'),
		'mensaje'    => $form->getValue('mensaje'),
      );
	  $this->redirect('aboutus/merci?email='.$form->getValue('email')."&name=".$form->getValue('name'));
    }
	else{
	  $this->setTemplate('contactez');
	}
  }
}
